package com.xiaok.mobileredis.async;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.UUID;

/**
 * @author xiaok
 * @create 2020--09-14 18:41
 */

@Service
public class AsynTaskExecuteService {
    @Async    // 这里进行标注为异步任务，在执行此方法的时候，会单独开启线程来执行
    public void f1() {
        System.out.println("f1 : " + Thread.currentThread().getName() + "   " + UUID.randomUUID().toString());
        try {
            Thread.sleep(new Random().nextInt(100));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Async
    public void f2() {
        System.out.println("f2 : " + Thread.currentThread().getName() + "   " + UUID.randomUUID().toString());
        try {
            Thread.sleep(100);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
